﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EventReminder.Client
{
    public partial class MonthForm : Form
    {
        private EventReminderController _controller;
        public MonthForm()
        {
            // TODO: change this so that other file does this somewhere else that runs MonthForm
            InitializeComponent();
            _controller = new EventReminderController(this);
            _controller.LogoutSucceeded += new EventHandler(HandleLogoutSucceeded);
        }

        protected override void OnCreateControl()
        {
            _controller.ShowLoginDialog();

            base.OnCreateControl();
        }

        private void HandleBtnOpen_Click(object sender, EventArgs e)
        {
            _controller.OpenDay(this.calMonth.TodayDate);
        }

        private void HandleButtonQuit_Click(object sender, EventArgs e)
        {
            _controller.Logout();
        }

        private void HandleLogoutSucceeded(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.Close();
            }
        }

        protected override void OnClosed(EventArgs e)
        {
            _controller.LogoutSucceeded -= new EventHandler(HandleLogoutSucceeded);
            base.OnClosed(e);
        }
    }
}
